package com.mindcraft.chat.message.config;

import com.alibaba.fastjson.JSONObject;
import com.mindcraft.chat.mapper.ImChatUserMessageMapper;
import com.mindcraft.chat.po.ImChatUserMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {

    @Autowired
    private ImChatUserMessageMapper messageMapper;

    @JmsListener(destination = "order.queue.message")
    private void receive(String message){

        System.out.println("已经接收到信息：" + message);

        // 将 JSON 字符串转换为 ImChatUserMessage 对象
        ImChatUserMessage chatRecord = JSONObject.parseObject(message, ImChatUserMessage.class);

        // 将消息保存到数据库
        messageMapper.insert(chatRecord);
    }
}
